import cv2
import numpy as np
import pyautogui
from PIL import ImageGrab
import time
from datetime import date, datetime, timedelta
from 子函数.yinru import douji
from 子函数.yinru import cs,zd ,yqfy,jr ,zb ,js ,sb ,yh ,ts ,bqds ,zd1 ,cjdw ,cj ,kszd ,qd ,jjtp ,jg ,yq ,di2zhang,di3zhang ,di4zhang ,di5zhang
from 子函数.yinru import di20zhang ,di21zhang ,di22zhang ,di23zhang ,ts1 ,daotubiao ,daotubiao1 ,zhanliping ,huodejiangli ,zaizhanchang ,haifangzhu ,sx ,tz ,xiaomao
from 子函数.yinru import jiejietupo ,liuxunzhang,jieshu,danjujieshu,qr1,时间下限,时间上限,feiliuxing,jieshou,time3,jingyanman,qx,douji,baoxiang,tanshouweizhi
from 子函数.yinru import chahao ,shoudong,doujijieshu

def 斗技():
    # 斗技
    img_rgb = np.array(ImageGrab.grab().convert('RGB'))#屏幕截图
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    # 斗技
    res = cv2.matchTemplate(img_gray, douji, cv2.TM_CCOEFF_NORMED)  # 大图 ，目标 ，模式
    threshold = 0.8  # 阈值 图片相识度
    loc = np.where(res >= threshold)
    # pyautogui.moveTo(random.randint(0, 1430), random.randint(0, 960))  # 鼠标移动到坐标位置
    for pt in zip(*loc[::-1]):
        # cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), )#在图片选中位置画线框
        pyautogui.moveTo(int(pt[0])+10, int(pt[1])+10)  # 鼠标移动到坐标位置
        pyautogui.click()  # 鼠标点击
        print("准备")

        break

    now = datetime.now()
    strnow = now.strftime('%Y-%m-%d %H:%M:%S')
    print("现在时间:", strnow[11:13])

    if (strnow[11:13] != "12")&(strnow[11:13] != "20"):
        print("没到时间")
        time.sleep(99999)

    # # 斗技没开放
    # img_rgb = np.array(ImageGrab.grab().convert('RGB'))#屏幕截图
    # img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    # # 斗技没开放
    # res = cv2.matchTemplate(img_gray, doujijieshu, cv2.TM_CCOEFF_NORMED)  # 大图 ，目标 ，模式
    # threshold = 0.8  # 阈值 图片相识度
    # loc = np.where(res >= threshold)
    # # pyautogui.moveTo(random.randint(0, 1430), random.randint(0, 960))  # 鼠标移动到坐标位置
    # for pt in zip(*loc[::-1]):
    #     # cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), )#在图片选中位置画线框
    #     pyautogui.moveTo(int(pt[0])+10, int(pt[1])+10)  # 鼠标移动到坐标位置
    #     pyautogui.click()  # 鼠标点击
    #     print("斗技没开放")
    #     time.sleep(60000)
    #     break



